package net.unix8.test;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;

import com.jfinal.kit.PathKit;

import net.unix8.constant.ConstantsValue;
import net.unix8.tool.FileProcess;
import net.unix8.tool.Tools;

public class MFileTtest {
	public static void test1(String file1){
		try {
			byte [][]dataFirst = new byte[3][];
			dataFirst[0] = Tools.readFiletoNByteArray(file1, ConstantsValue.HEAD_LENGTH,n);//从start开始读取数据x
			dataFirst[1] = Tools.readFiletoNByteArray(file1, ConstantsValue.HEAD_LENGTH + 4000l * 4l,n);//从start开始读取数据y
			dataFirst[2] = Tools.readFiletoNByteArray(file1, ConstantsValue.HEAD_LENGTH + 4000 * 4l * 2l ,n);
			//System.out.println(Arrays.toString(dataFirst[0]));
			//System.out.println(Arrays.toString(dataFirst[1]));
			System.out.println(Arrays.toString(dataFirst[2]));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	private static long n = 10 * 4;
public static void test(String file1){
	try {
		byte [][]dataFirst = new byte[3][];
		dataFirst[0] = Tools.readFiletoNByteArray(file1, ConstantsValue.HEAD_LENGTH+4000*4,n);//从start开始读取数据x
		dataFirst[1] = Tools.readFiletoNByteArray(file1, ConstantsValue.HEAD_LENGTH + 8000l * 4l+4000*4,n);//从start开始读取数据y
		dataFirst[2] = Tools.readFiletoNByteArray(file1, ConstantsValue.HEAD_LENGTH + 8000l * 4l * 2l+4000*4 ,n);
		//System.out.println(Arrays.toString(dataFirst[0]));
		//System.out.println(Arrays.toString(dataFirst[1]));
		System.out.println(Arrays.toString(dataFirst[2]));
	} catch (IOException e) {
		e.printStackTrace();
	}
}
public  static void sortFilesWtihDescending(File[] files) {
	  Arrays.sort(files, new Comparator<File>() {
	    public int compare(File sa, File sb) {		
	      File f1 = sa;
	      File f2 = sb;
	  
	      if (f1.getName().compareTo(f2.getName()) >0) {
	        return 1;
	      } else {
	        return -1;
	      }
	      }});
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		System.out.println("----------------------------------------------------------------------------------------------------------------------------------------\n");
		//test1("F:\\2017\\LinuxCenterServer\\WebRoot\\data\\192.168.127.31\\20170517162440");
		//System.out.println("--------------------------------------------------------------------------------------------------------------\n");
		//test("F:\\2017\\LinuxCenterServer\\WebRoot\\mdata\\192.168.127.31\\20170517162438");
		//FileProcess.readHead("/Users/apple/Documents/ME/git/WebRoot/sdata/192.168.127.171/20170825140224");
		//FileProcess.mergeFile("/Users/apple/Documents/ME/git/WebRoot/sdata/192.168.127.171/20170826152443", 
		//		"/Users/apple/Documents/ME/git/WebRoot/sdata/192.168.127.171/20170826152503");
		/*
		byte [][]dataSeconod = new byte[3][];
		byte []b1 = {1,2,3};
		byte []b2 = {4,5,6};
		byte []b3 = {7,8,9};
		dataSeconod[0] = b1;//从start开始读取数据x
		dataSeconod[1] = b2;//从start开始读取数据y
		dataSeconod[2] = b3;//从start开始读取数据z	
		byte [][]dataSeconod1 = new byte[3][];
		byte []b11 = {11,12,13};
		byte []b21 = {14,15,16};
		byte []b31 = {17,18,19};
		dataSeconod1[0] = b11;//从start开始读取数据x
		dataSeconod1[1] = b21;//从start开始读取数据y
		dataSeconod1[2] = b31;//从start开始读取数据z	
		byte [][] mergeData = Tools.ByteArrayInsert(dataSeconod, dataSeconod1);//合并
		System.out.println(Arrays.toString(mergeData[0]));
		System.out.println(Arrays.toString(mergeData[1]));
		System.out.println(Arrays.toString(mergeData[2]));*/
		String hostString = "192.168.127.171";
		String pathString = PathKit.getWebRootPath() + "/sdata/" + hostString+"/";
		File fileSdata = new File(pathString);    
		File[] tempList = fileSdata.listFiles();
		sortFilesWtihDescending(tempList);
		for(int i = 0; i < tempList.length;++i) {
			System.out.println(tempList[i].getName());
		}
	}

}
